<html>
<head><meta charset="utf-8"><title>zeroed vs MaybeUninit · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html">zeroed vs MaybeUninit</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="180832394"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180832394" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180832394">(Nov 15 2019 at 13:41)</a>:</h4>
<p>I don't think we're doing <code>mem::zeroed</code>. Instead we'll do <code>MaybeUninit::zeroed</code></p>



<a name="180842384"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180842384" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180842384">(Nov 15 2019 at 15:28)</a>:</h4>
<p>Well that is a distressing and poor decision :(</p>



<a name="180843169"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180843169" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180843169">(Nov 15 2019 at 15:34)</a>:</h4>
<p>Why? It will encourage people to use the better supported version.</p>



<a name="180843221"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180843221" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180843221">(Nov 15 2019 at 15:34)</a>:</h4>
<p>Thinking of other deprecated functions, will <code>thread::sleep</code> be const? :-)</p>



<a name="180843671"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180843671" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180843671">(Nov 15 2019 at 15:39)</a>:</h4>
<p><span aria-label="upside down" class="emoji emoji-1f643" role="img" title="upside down">:upside_down:</span> uh sure we could do that</p>



<a name="180845171"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180845171" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180845171">(Nov 15 2019 at 15:55)</a>:</h4>
<p>Nice. Then I can gradually speed up the compile times of my code.</p>



<a name="180845520"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180845520" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180845520">(Nov 15 2019 at 15:59)</a>:</h4>
<p>nah, it won't do a thing</p>



<a name="180846228"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180846228" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180846228">(Nov 15 2019 at 16:06)</a>:</h4>
<p>There's no point in making the old version const fn because to use that you'd need to be on a new compiler which has MaybeUninit already anyway right?</p>



<a name="180846561"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180846561" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180846561">(Nov 15 2019 at 16:10)</a>:</h4>
<p>yes</p>



<a name="180846596"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180846596" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180846596">(Nov 15 2019 at 16:11)</a>:</h4>
<p>not giving features to deprecated things will help adoption of the replacement, too</p>



<a name="180858363"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180858363" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180858363">(Nov 15 2019 at 18:27)</a>:</h4>
<p>We didn't deprecate <code>mem::zeroed</code> though, only <code>mem::uninitialized</code>.</p>



<a name="180858388"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180858388" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180858388">(Nov 15 2019 at 18:27)</a>:</h4>
<p>Because <code>mem::zeroed</code> has valid use cases with FFI.</p>



<a name="180858485"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180858485" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180858485">(Nov 15 2019 at 18:28)</a>:</h4>
<p>hm, but so does uninitialized, right? My impression was that the two are essentially equivalent...</p>



<a name="180858488"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180858488" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180858488">(Nov 15 2019 at 18:28)</a>:</h4>
<p>Maybe I misunderstood</p>



<a name="180859107"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180859107" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180859107">(Nov 15 2019 at 18:36)</a>:</h4>
<p>Basically <code>*val = mem::zeroed();</code> is equivalent to <code>memset(&amp;val, 0, sizeof(val));</code></p>



<a name="180859291"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180859291" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180859291">(Nov 15 2019 at 18:38)</a>:</h4>
<p>sure, I understand that, but I'd expect us to push users towards <code>MaybeUninit::zeroed().assume_init()</code>. I guess that's not really better in any way.</p>



<a name="180859329"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180859329" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180859329">(Nov 15 2019 at 18:39)</a>:</h4>
<p>though arguably you should pass the ptr into FFI if you can rather than the zeroed struct (and then afterwards assume_init())</p>



<a name="180868729"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180868729" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180868729">(Nov 15 2019 at 20:29)</a>:</h4>
<p>that's way longer to type for no actual gain in clarity. the argument could be made that clarity is significantly reduced in fact</p>



<a name="180868893"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180868893" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180868893">(Nov 15 2019 at 20:31)</a>:</h4>
<p>essentially any C struct from FFI is safe to be zeroed (in the "data validity" sense), and you often set fields of the structure on your side of things before passing the pointer to FFI</p>



<a name="180869015"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180869015" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180869015">(Nov 15 2019 at 20:32)</a>:</h4>
<p>yeah, that's true</p>



<a name="180869031"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180869031" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180869031">(Nov 15 2019 at 20:32)</a>:</h4>
<p>though it is sometimes convenient to have references and such in FFI layers which can't then be zeroed</p>



<a name="180869095"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180869095" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180869095">(Nov 15 2019 at 20:33)</a>:</h4>
<p>that danger is already being fixed: <a href="https://github.com/rust-lang/rust/pull/66059" target="_blank" title="https://github.com/rust-lang/rust/pull/66059">https://github.com/rust-lang/rust/pull/66059</a></p>



<a name="180869179"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180869179" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180869179">(Nov 15 2019 at 20:34)</a>:</h4>
<p>i wish that rust language people would please stop thinking that core::mem::zeroed is somehow not good to use</p>



<a name="180869199"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180869199" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180869199">(Nov 15 2019 at 20:35)</a>:</h4>
<p>it is a better API than MaybeUninit::zeroed().assume_init()</p>



<a name="180869231"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180869231" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180869231">(Nov 15 2019 at 20:35)</a>:</h4>
<p>just because it is less verbose and you see the point of the expression more easily when reading the page</p>



<a name="180869364"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180869364" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180869364">(Nov 15 2019 at 20:37)</a>:</h4>
<p>you know this is zulip and you can fork a thread instead of hijacking the const fn wishlist for hashing out different opinions on things ;)</p>



<a name="180869390"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180869390" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180869390">(Nov 15 2019 at 20:37)</a>:</h4>
<p>/me had thought this was just about zeroed :)</p>



<a name="180869494"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180869494" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180869494">(Nov 15 2019 at 20:38)</a>:</h4>
<p>ah right, is there a way to fork a thread after the fact?</p>



<a name="180869507"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180869507" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180869507">(Nov 15 2019 at 20:38)</a>:</h4>
<p>i did not mean to clog up the list</p>



<a name="180869509"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180869509" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180869509">(Nov 15 2019 at 20:38)</a>:</h4>
<p>trying to figure that out right now, I've seen ppl do it before</p>



<a name="180869673"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180869673" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180869673">(Nov 15 2019 at 20:41)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> done -- not very intuitive</p>



<a name="180869695"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180869695" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180869695">(Nov 15 2019 at 20:41)</a>:</h4>
<p>you want to do "view source / edit topic" and say "all later"</p>



<a name="180869773"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180869773" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180869773">(Nov 15 2019 at 20:42)</a>:</h4>
<p>oh, I found the editing, but not something that would do the whole shebang</p>



<a name="180869982"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180869982" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180869982">(Nov 15 2019 at 20:45)</a>:</h4>
<p>Anyway, wrt safe uses of <code>zeroed</code>, instead of asking whether dangerous API or obviously dangerous API is worse, shouldn't we ask "can we figure out a way to make zero init safe for the types where it is?"?</p>



<a name="180870168"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180870168" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180870168">(Nov 15 2019 at 20:47)</a>:</h4>
<p>I think there's definitely some discussion around that and an auto trait for it</p>



<a name="180870175"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180870175" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180870175">(Nov 15 2019 at 20:47)</a>:</h4>
<p>in theory we could get pretty much 100% fidelity since the compiler knows all cases of "nonzero"</p>



<a name="180870250"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180870250" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180870250">(Nov 15 2019 at 20:48)</a>:</h4>
<p>omg right, we could even detect enums that can be zeroed</p>



<a name="180870266"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180870266" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180870266">(Nov 15 2019 at 20:48)</a>:</h4>
<p>although for <code>repr(Rust)</code> types that's bad</p>



<a name="180870271"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180870271" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180870271">(Nov 15 2019 at 20:48)</a>:</h4>
<p>probably needs someone to write up an RFC, there's probably issues I'm not thinking of :)</p>



<a name="180870285"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180870285" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180870285">(Nov 15 2019 at 20:49)</a>:</h4>
<p>because compiler updates can then break trait resolution</p>



<a name="180870310"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180870310" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180870310">(Nov 15 2019 at 20:49)</a>:</h4>
<p>hm, sure, though I imagine you would perhaps say "don't use mem zeroed generally"</p>



<a name="180870313"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180870313" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180870313">(Nov 15 2019 at 20:49)</a>:</h4>
<p>or even just reordering of enum variants, which isn't a breaking change in any definition I think</p>



<a name="180870342"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180870342" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180870342">(Nov 15 2019 at 20:50)</a>:</h4>
<p><code>trait Zero</code> and <code>auto trait Zeroable {}</code> and <code>mem::zeroed::&lt;T: Zero&gt;()</code> with the first you need to explicitly implement</p>



<a name="180870390"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180870390" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180870390">(Nov 15 2019 at 20:50)</a>:</h4>
<p>yea, but if a compiler update changes <code>Option&lt;usize&gt;::None</code> into <code>Option&lt;usize&gt;::Some(0)</code>, that's bad</p>



<a name="180870407"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180870407" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180870407">(Nov 15 2019 at 20:50)</a>:</h4>
<p>sure, we'd error on the <code>impl Zero for Foo</code></p>



<a name="180870413"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180870413" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180870413">(Nov 15 2019 at 20:50)</a>:</h4>
<p>and have some guidelines -- maybe e.g. enums are never zero-safe</p>



<a name="180870415"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180870415" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180870415">(Nov 15 2019 at 20:50)</a>:</h4>
<p>oh it's all opt-in?</p>



<a name="180870425"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180870425" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180870425">(Nov 15 2019 at 20:50)</a>:</h4>
<p>right, yeah, the safety aspect</p>



<a name="180870430"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180870430" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180870430">(Nov 15 2019 at 20:50)</a>:</h4>
<p>but it's always safe to opt-in</p>



<a name="180870447"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180870447" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180870447">(Nov 15 2019 at 20:51)</a>:</h4>
<p>well <code>repr(C)</code> enums can be zero safe</p>



<a name="180870553"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180870553" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180870553">(Nov 15 2019 at 20:52)</a>:</h4>
<p>sure - basically I'm saying that you'd say that for some types maybe we auto do it</p>



<a name="180870560"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180870560" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180870560">(Nov 15 2019 at 20:52)</a>:</h4>
<p>e.g. a repr C struct with <code>u32</code> or so fields</p>



<a name="180870594"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180870594" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180870594">(Nov 15 2019 at 20:53)</a>:</h4>
<p>kk</p>



<a name="180870605"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180870605" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180870605">(Nov 15 2019 at 20:53)</a>:</h4>
<p>but if you get into repr(Rust) types, maybe we error out unless explicitly enabled</p>



<a name="180870624"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180870624" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180870624">(Nov 15 2019 at 20:53)</a>:</h4>
<p>(and that explicit enabler is not unsafe ever, just a stability promise in some sense)</p>



<a name="180870741"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180870741" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180870741">(Nov 15 2019 at 20:54)</a>:</h4>
<p>the compiler can't make that stability promise</p>



<a name="180870843"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180870843" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180870843">(Nov 15 2019 at 20:55)</a>:</h4>
<p>So what I'm getting at is that I'm saying "I will not make this non-zeroable"</p>



<a name="180870900"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180870900" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180870900">(Nov 15 2019 at 20:55)</a>:</h4>
<p>e.g. maybe it's repr(Rust) struct</p>



<a name="180870912"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180870912" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180870912">(Nov 15 2019 at 20:55)</a>:</h4>
<p>but I know that it'll always be valid at zero</p>



<a name="180870913"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180870913" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180870913">(Nov 15 2019 at 20:55)</a>:</h4>
<p>ah</p>



<a name="180870942"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180870942" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180870942">(Nov 15 2019 at 20:55)</a>:</h4>
<p>right, but what a zeroed value means may change arbitrarily</p>



<a name="180870954"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180870954" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180870954">(Nov 15 2019 at 20:55)</a>:</h4>
<p>well, for some things, yes</p>



<a name="180870976"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180870976" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180870976">(Nov 15 2019 at 20:56)</a>:</h4>
<p>but e.g. a <code>u32</code> I could imagine we promise is always safe to zero</p>



<a name="180871053"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180871053" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180871053">(Nov 15 2019 at 20:56)</a>:</h4>
<p>yea, also any struct array or tuple I think</p>



<a name="180871063"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180871063" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180871063">(Nov 15 2019 at 20:56)</a>:</h4>
<p>so if I have <code>struct Foo(u32);</code> I could promise that's safe to zero</p>



<a name="180871064"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180871064" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180871064">(Nov 15 2019 at 20:56)</a>:</h4>
<p>I only see problems with enums</p>



<a name="180871079"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180871079" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180871079">(Nov 15 2019 at 20:56)</a>:</h4>
<p>well, things containing enums, right?</p>



<a name="180871084"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180871084" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180871084">(Nov 15 2019 at 20:56)</a>:</h4>
<p>right</p>



<a name="180871094"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180871094" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180871094">(Nov 15 2019 at 20:56)</a>:</h4>
<p>recursively</p>



<a name="180871134"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180871134" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180871134">(Nov 15 2019 at 20:57)</a>:</h4>
<p>Do we optimize structs ever today by reusing padding fields?</p>



<a name="180871191"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180871191" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180871191">(Nov 15 2019 at 20:57)</a>:</h4>
<p>I guess probably no</p>



<a name="180871226"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180871226" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180871226">(Nov 15 2019 at 20:57)</a>:</h4>
<p>since you need to be able to take references</p>



<a name="180871343"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180871343" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180871343">(Nov 15 2019 at 20:58)</a>:</h4>
<p>and in any case we'd never make zero magically invalid I suspect</p>



<a name="180871377"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180871377" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180871377">(Nov 15 2019 at 20:59)</a>:</h4>
<p>yeah, I agree that only enums are presently an issue</p>



<a name="180871404"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180871404" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180871404">(Nov 15 2019 at 20:59)</a>:</h4>
<p>though maybe e.g. references are also interesting</p>



<a name="180871421"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180871421" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180871421">(Nov 15 2019 at 20:59)</a>:</h4>
<p>since we have "more than one" bit in them which we currently might assume we're free to use for enum optimization (eventually)</p>



<a name="180871426"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180871426" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180871426">(Nov 15 2019 at 21:00)</a>:</h4>
<p>due to them being well-aligned</p>



<a name="180871492"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180871492" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180871492">(Nov 15 2019 at 21:00)</a>:</h4>
<p>so <code>&amp;Align16</code> has not just zero as an invalid bit pattern</p>



<a name="180871506"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180871506" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180871506">(Nov 15 2019 at 21:00)</a>:</h4>
<p>wait slow down, <a href="https://github.com/rust-lang/rust/pull/66059" target="_blank" title="https://github.com/rust-lang/rust/pull/66059">https://github.com/rust-lang/rust/pull/66059</a> Ralf is already working on type based panic if it would be invalid</p>



<a name="180871535"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180871535" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180871535">(Nov 15 2019 at 21:01)</a>:</h4>
<p>right, but that's just at runtime</p>



<a name="180871537"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180871537" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180871537">(Nov 15 2019 at 21:01)</a>:</h4>
<p>we're discussing making <code>zeroed</code> entirely safe</p>



<a name="180871542"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180871542" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180871542">(Nov 15 2019 at 21:01)</a>:</h4>
<p>I'm not sure if that affects the rest of this since you said quite a bit in like 5min XD</p>



<a name="180871553"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180871553" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180871553">(Nov 15 2019 at 21:01)</a>:</h4>
<p>oh, fully safe at compile time</p>



<a name="180871558"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180871558" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180871558">(Nov 15 2019 at 21:01)</a>:</h4>
<p>"yes please"</p>



<a name="180871571"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180871571" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180871571">(Nov 15 2019 at 21:01)</a>:</h4>
<p>with a trait!</p>



<a name="180871693"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180871693" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180871693">(Nov 15 2019 at 21:03)</a>:</h4>
<p>I wonder if we could even get e.g. <code>#[repr(ptr_packed)] struct Foo(&amp;Align16, bool, bool, bool, bool);</code> such that the bools go into the ptr 'slots' transparently</p>



<a name="180871788"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180871788" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180871788">(Nov 15 2019 at 21:04)</a>:</h4>
<p>wait how does &amp;Align16 have an invalid bit pattern other than zero?</p>



<a name="180871844"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180871844" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180871844">(Nov 15 2019 at 21:04)</a>:</h4>
<p>you know that the bottom bits of the pointer can never be anything than zero, right?</p>



<a name="180871880"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180871880" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180871880">(Nov 15 2019 at 21:04)</a>:</h4>
<p>e.g. <code>0x1</code> is not a valid value for that reference</p>



<a name="180872012"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180872012" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180872012">(Nov 15 2019 at 21:06)</a>:</h4>
<p>(nor <code>0x.....1</code>, etc.)</p>



<a name="180872898"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180872898" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180872898">(Nov 15 2019 at 21:16)</a>:</h4>
<p>ahhh</p>



<a name="180872916"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180872916" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180872916">(Nov 15 2019 at 21:16)</a>:</h4>
<p>right, so it has a number of bits of niche</p>



<a name="180872926"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180872926" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180872926">(Nov 15 2019 at 21:16)</a>:</h4>
<p>does Rust actually use that currently?</p>



<a name="180872930"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180872930" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180872930">(Nov 15 2019 at 21:16)</a>:</h4>
<p>I believe this is not generally true (currently)</p>



<a name="180872945"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180872945" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180872945">(Nov 15 2019 at 21:17)</a>:</h4>
<p>i.e., we don't use it</p>



<a name="180872980"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180872980" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180872980">(Nov 15 2019 at 21:17)</a>:</h4>
<p>because it means you can't take a reference to that field</p>



<a name="180873002"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180873002" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180873002">(Nov 15 2019 at 21:17)</a>:</h4>
<p>(since then unrelated code would need to not "just" dereference it, which has a cost)</p>



<a name="180879356"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180879356" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180879356">(Nov 15 2019 at 22:40)</a>:</h4>
<blockquote>
<p>I think there's definitely some discussion around that and an auto trait for it</p>
</blockquote>
<p>An auto trait would easily brick a crate like <a href="https://docs.rs/refl/0.2.0/refl/struct.Id.html" target="_blank" title="https://docs.rs/refl/0.2.0/refl/struct.Id.html">https://docs.rs/refl/0.2.0/refl/struct.Id.html</a> (if it used <code>*mut T</code> instead of function pointers, which a previous iteration did) rendering it unsound</p>



<a name="180879392"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180879392" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180879392">(Nov 15 2019 at 22:41)</a>:</h4>
<p>it gives you the ability to conjure up values for types that the crate author didn't want to enable</p>



<a name="180879406"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180879406" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180879406">(Nov 15 2019 at 22:41)</a>:</h4>
<p>so it cannot be a safe API</p>



<a name="180879412"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180879412" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180879412">(Nov 15 2019 at 22:41)</a>:</h4>
<p>hm, I think that's not entirely true</p>



<a name="180879465"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180879465" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180879465">(Nov 15 2019 at 22:42)</a>:</h4>
<p>i.e., we could presumably say that such types would need to be disabled somehow for it</p>



<a name="180879508"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180879508" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180879508">(Nov 15 2019 at 22:42)</a>:</h4>
<p>in any case, I think saying that the things you need to guarantee for safety are just "library conditions on the existence of this type" are much easier to satisfy, in general, than "make sure there are no references etc in here anywhere"</p>



<a name="180879511"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180879511" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180879511">(Nov 15 2019 at 22:42)</a>:</h4>
<p>auto traits work structurally, so you'll need some structural condition to make the implementations unavailable</p>



<a name="180879526"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180879526" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180879526">(Nov 15 2019 at 22:43)</a>:</h4>
<p>I guess that's true, since it would be backwards incompatible</p>



<a name="180879539"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180879539" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180879539">(Nov 15 2019 at 22:43)</a>:</h4>
<p>but even if it stays unsafe but we reduce the things you need to prove that's still pretty amazing</p>



<a name="180879548"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180879548" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180879548">(Nov 15 2019 at 22:43)</a>:</h4>
<p>And Ralf's work here is already moving us closer</p>



<a name="180879606"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180879606" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180879606">(Nov 15 2019 at 22:44)</a>:</h4>
<p>Ralf's PR is cursed ^^</p>



<a name="180879624"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180879624" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180879624">(Nov 15 2019 at 22:44)</a>:</h4>
<p>well it just broke cargo</p>



<a name="180879635"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180879635" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180879635">(Nov 15 2019 at 22:44)</a>:</h4>
<p>i.e., revealed unsoundness in some dep</p>



<a name="180879656"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180879656" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180879656">(Nov 15 2019 at 22:45)</a>:</h4>
<p>fun stuff</p>



<a name="180904899"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180904899" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180904899">(Nov 16 2019 at 09:27)</a>:</h4>
<p><span class="user-mention" data-user-id="116122">@simulacrum</span> </p>
<blockquote>
<p>hm, but so does uninitialized, right? My impression was that the two are essentially equivalent...</p>
</blockquote>
<p>no. <code>mem::uninitialized</code> is pretty much always wrong, including in FFI. there are very few types for this this is not insta-UB. (basically, <code>let m: MaybeUninit&lt;T&gt; = mem::uninitialized();</code> is okay, but that's about it)</p>



<a name="180904947"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180904947" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180904947">(Nov 16 2019 at 09:28)</a>:</h4>
<blockquote>
<p>sure, I understand that, but I'd expect us to push users towards <code>MaybeUninit::zeroed().assume_init()</code>. I guess that's not really better in any way.</p>
</blockquote>
<p>actually <code>mem::zeroed</code> will do better run-time checks once <a href="https://github.com/rust-lang/rust/pull/66059" target="_blank" title="https://github.com/rust-lang/rust/pull/66059">https://github.com/rust-lang/rust/pull/66059</a> lands, so between the two of them, <code>mem::zeroed</code> is better ;)<br>
<code>MaybeUninit</code> provides type-based tracking of initializedness; if you don't need that for correctness (which can indeed be the case if 0-initialization is allowed for your types), there is no reason to use it.</p>
<blockquote>
<p>though arguably you should pass the ptr into FFI if you can rather than the zeroed struct (and then afterwards assume_init())</p>
</blockquote>
<p>yes.</p>



<a name="180905103"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/180905103" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#180905103">(Nov 16 2019 at 09:32)</a>:</h4>
<p>so I am actually fine with making <code>mem::zeroed</code> a <code>const fn</code> (maybe we could hack something to do a full validity check for such values, which generally for perf reasons we do not do in CTFE). however I'd prefer to not implement the <code>init</code> intrinsic in CTFE, it's quite a mess; instead we should implement <code>mem::zeroed</code> as <code>MaybeUninit::zeroed().assume_init()</code> and make the latter a <code>const fn</code>.</p>



<a name="181287490"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/181287490" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Elichai Turkel <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#181287490">(Nov 21 2019 at 09:21)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> I like your idea :) I think using <code>repr(C)</code> is better than a Zeroable trait.<br>
(although it might push some users to start putting <code>repr(C)</code> just to be able to zeroize)<br>
that way we can just lint if <code>mem::zeroed()</code>  is used on any non <code>repr(C)</code> type</p>



<a name="181717430"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/zeroed%20vs%20MaybeUninit/near/181717430" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/zeroed.20vs.20MaybeUninit.html#181717430">(Nov 23 2019 at 14:15)</a>:</h4>
<p>repr(C) is not an appropriate way to track if a type can be zeroed</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>